package com.iot.common.feign;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.iot.common.core.constant.SecurityConstants;

//@Configuration
public class FeignClientRequestInterceptor implements RequestInterceptor {
	@Override
	public void apply(RequestTemplate requestTemplate) {
		ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
		HttpServletRequest request = attributes.getRequest();
		requestTemplate.header(SecurityConstants.TOKEN_HEADER, request.getHeader(SecurityConstants.TOKEN_HEADER));
	}
}
